library Wave13b initializer init requires LegacySystem, DeltaUtils

    private function Wave13c takes nothing returns nothing
        local integer i = 1
        local integer i2 = 1
        local unit BlackHawk1
        local unit BlackHawk2
        local location l = Location(12620.0,8740.0)
        local location l2 = Location(13293.0,8088.0)
        local real x = GetLocationX(l)
        local real y = GetLocationY(l)
        local real x2 = GetLocationX(l2)
        local real y2 = GetLocationY(l2)
        local real angle
        set udg_CurrentWave = 13
        set udg_Visibility = 66
        call IntermissionRestore()
        set udg_Visibility = 67
        call IntermissionRestore()
        call GenericActions.execute()
        loop
            exitwhen i>4
            call SpawnRectRandom(gg_rct_ADTSpawnWest,Player(13),'n00N',GetRandomInt(1,4)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnWest,Player(13),'n00A',udg_Spawn)
			
            if i==2 then
                call RadioChat(udg_DeltaLeader, 6.0, "|cfff3ad00SSgt. Thompson|r : Make your shots count. Our ammunition supplies are better utilized on the Aegis turrets." )
            endif
            if i==3 then
                call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : Fill up the ammunition in those turrets! We'll be sitting ducks if they run out of rounds." )
            endif

            call SpawnRectRandom(gg_rct_ADTSpawnEast,Player(13),'n00N',GetRandomInt(1,3)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnSouth,Player(13),'n00N',GetRandomInt(1,3)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnNorth,Player(14),'n00N',GetRandomInt(1,5)*udg_Spawn)
            if GetRandomInt(0,4)==1 then
                call GankMarine(Player(14),'u005',2+udg_Spawn,1700,2500)
            endif
            call PolledWait(12.0*udg_Pace)
            set i=i+1
        endloop

		call PolledWait(10.0*udg_Pace)
        if udg_Players==0 then
            return
        endif
        if GetWidgetLife(udg_AITarget)<0.405 then
            if GetWidgetLife(udg_AirfieldF22[1])>0.405 then
                call KillUnit(udg_AirfieldF22[1])
            endif
            if GetWidgetLife(udg_AirfieldF22[2])>0.405 then
                call KillUnit(udg_AirfieldF22[2])
            endif
            call ADTCleanup()
            call DeltaExit.execute()
            
            call ExecuteRegisteredFunction("Wave14a1")
            //call Wave14a.execute()
            
            // yanked from RevalationSpawnControl.j
            if (GetPlayerState(Player(13), PLAYER_STATE_RESOURCE_FOOD_USED)<80 and GetPlayerState(Player(14), PLAYER_STATE_RESOURCE_FOOD_USED)<80) then
                call RandomSpawn('n00A',1,GetRandomInt(0, IMaxBJ(3, udg_Spawn) )) //Tartarus
                call GankMarine(Player(13),'n004',udg_Spawn,1000,1800) //Zombie #2
                call RandomSpawn('u005',1,GetRandomInt(0,udg_Spawn)) //Gargolye #2
                call RandomSpawn('n00N',1,GetRandomInt(0,2)) //Mass HP Zombie
            endif
            call SpawnShredder ()
            call TriggerSleepAction(GetRandomReal(0.0,15.0))
            call LightningAmbience.execute()
            
            return
        endif
        set BlackHawk1 = CreateUnit(Player(11),'h009',9694.0,6729.0,35.0)
        set BlackHawk2 = CreateUnit(Player(11),'h009',9877.0,6342.0,35.0)
        call RemoveGuardPosition(BlackHawk1)
        call RemoveGuardPosition(BlackHawk2)
        call TriggerSleepAction(0.)
        call IssuePointOrderLoc( BlackHawk1, "move", l )
        call IssuePointOrderLoc( BlackHawk2, "move", l2 )
        call StartSound(gg_snd_BlackHawkRotor)
        call PolledWait(2.25)
        call StartSound(gg_snd_BlackHawk)
        call PolledWait(3.25)
        call SetForceAllianceStateBJ( bj_FORCE_PLAYER[11], udg_UnknownEntities, bj_ALLIANCE_ALLIED )
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : The pilots are here." )
        call SetUnitFlyHeight( BlackHawk1, 0.0, 125.0 )
        call SetUnitFlyHeight( BlackHawk2, 0.0, 125.0 )
        call SmoothUnitResize(BlackHawk1,1.45,1.55,4)
        call SmoothUnitResize(BlackHawk2,1.45,1.55,4)
        call PolledWait(3.)
        set udg_LZPoint = l
        call BlackHawkWashOff.execute()
        call TriggerSleepAction(0)
        set udg_LZPoint = l2
        call BlackHawkWashOff.execute()
        call PlaySoundAtPointBJ( gg_snd_BlackHawkLand, 100.0, l, 15.0 )
        call TriggerSleepAction(0)
        call PlaySoundAtPointBJ( gg_snd_BlackHawkLand, 100.0, l2, 15.0 )
        call PolledWait(2.5)
        set i = 1
        loop
            exitwhen i>4
            set angle = 360.0*( ( I2R(i) - 1 ) / I2R(4) )
            set udg_Pilot[i2] = CreateUnit(Player(11),'z006',GetLocationX(l)+80.0,GetLocationY(l)-175.0,0.0)
            call SetLoadState(I2S(GetHandleId(udg_Pilot[i2])),1)
            call IssuePointOrder( udg_Pilot[i2], "move", x + (325.0*Cos(angle*0.01745)), y + (325.0*Sin(angle*0.01745)) )
            set i2 = i2 + 1
            set udg_Pilot[i2] = CreateUnit(Player(11),'z006',GetLocationX(l2)+80.0,GetLocationY(l2)-175.00,0.0)
            call SetLoadState(I2S(GetHandleId(udg_Pilot[i2])),1)
            call IssuePointOrder( udg_Pilot[i2], "move", x2 + (325.0*Cos(angle*0.01745)), y2 + (325.0*Sin(angle*0.01745)) )
            set i2 = i2 + 1
            if GetRandomInt(0,1)==1 then
                call TriggerSleepAction(0)
            endif
            set i=i+1
        endloop
        call SetForceAllianceStateBJ( bj_FORCE_PLAYER[11], udg_UnknownEntities, bj_ALLIANCE_UNALLIED )
        set i=1
        set i2=1
        loop
            exitwhen i>3
            if GetWidgetLife(udg_AH1Cobra[i])>0.405 then
                set x = GetUnitX(udg_AH1Cobra[i])
                set y = GetUnitY(udg_AH1Cobra[i])
                call IssuePointOrder(udg_Pilot[i2],"move",x,y)
                set i2=i2+1
                call IssuePointOrder(udg_Pilot[i2],"move",x,y)
                set i2=i2+1
            endif
            set i=i+1
        endloop
        call IssuePointOrder(udg_Pilot[7], "move", 11180.0, 9707.0)
        call IssuePointOrder(udg_Pilot[8], "move", 11591.0, 9374.0)
        set udg_LZPoint = l
        call BlackHawkWashOff.execute()
        call TriggerSleepAction(0.)
        set udg_LZPoint = l2
        call BlackHawkWashOff.execute()
        call SetUnitFlyHeight(BlackHawk1,800.0,200.0)
        call SetUnitFlyHeight(BlackHawk2,800.0,200.0)
        call SmoothUnitResize(BlackHawk1,1.55,1.45,3)
        call SmoothUnitResize(BlackHawk2,1.55,1.45,3)
        call IssuePointOrder( BlackHawk1, "move", 14837.0, 12023.0 )
        call IssuePointOrder( BlackHawk2, "move", 14837.0, 10616.0 )
        call PolledWait(5.)
        call RemoveUnit(BlackHawk1)
        call RemoveUnit(BlackHawk2)
        call RemoveLocation(l)
        call RemoveLocation(l2)
        set l = null
        set l2 = null
        set BlackHawk1 = null
        set BlackHawk2 = null
        if udg_Players!=0 and GetWidgetLife(udg_AITarget)>0.405 then
            call ExecuteRegisteredFunction("Wave14c")
            //call Wave14c.execute()
        else
            call ADTCleanup()
            call DeltaExit.execute()
            call ExecuteRegisteredFunction("Wave14a1")
            //call Wave14a.execute()
            call SetRevelationSpawnEnabled(true)
        endif
    endfunction

    private function Wave13b takes nothing returns nothing
        local integer i
        local integer i2 = GetRandomInt(1, udg_Players)
        set udg_CurrentWave = 13
        set udg_IntenseSpawn = 1
        set udg_DMKills[1] = 0
        set udg_Visibility = 66
        call IntermissionRestore()
        set udg_Visibility = 67
        call IntermissionRestore()
        call GenericActions.execute()
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : The last component is being airdropped." )
        call PolledWait(10.0*udg_Pace)
        call M242Drop.execute()
        call RandomSpawn('z002',1,udg_Players) //Slasher
        call RandomSpawn('n00N',1,GetRandomInt(0, 1)) //Mass HP Zombie
        if udg_SquadXP>50000 then
            call RandomSpawn('e00Q',2,udg_Spawn) // Parasite Mound
        endif
        call PolledWait(10.0*udg_Pace)
        set udg_Visibility = 69
        call IntermissionRestore()
        if (getBoolean(null,"ENGPresent")==false) then
            call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : Only a trained Engineer can assemble all the parts. We'll have to get an Operations Manual." )
        endif
        call PolledWait(80.0*udg_Pace)
        if udg_Players>1 then
            set i = GetRandomInt(1, udg_Players)
            call FieldChat(udg_Hero[udg_Sorted[i]], 8, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : I hate to admit it. I feel safer with the D-Boys." )
            loop
                exitwhen i2!=i
                set i2 = GetRandomInt(1,udg_Players)
            endloop
            call PolledWait(4.0)
            call FieldChat(udg_Hero[udg_Sorted[i2]], 5, udg_Pcolors[udg_Sorted[i2]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i2])) + "|r : You're not alone." )
        endif
        set udg_myloc = GetRandomLocInRect(udg_PlayerSpawnBoundary)
        set udg_Boss = CreateUnitAtLoc(Player(14),'U009',udg_myloc,0) //Atlas
        call SuspendHeroXP(udg_Boss, true)
        call RemoveLocation(udg_myloc)
        call PolledWait(80.0*udg_Pace)
        call RandomSpawn('n00C',1,2) //Female
        if udg_Players!=0 then
            if udg_DeltaLeader==null then
                call DeltaExit.execute()
                
                call ExecuteRegisteredFunction("Wave14a1")
                //call Wave14a.execute()
                call SetDeltaSpawnEnabled(false)
                //call DisableTrigger(gg_trg_Delta_Wave_Spawn)
                call SetRevelationSpawnEnabled(true)
            else
                call ExecuteRegisteredFunction("Wave14b")
                //call Wave14b.execute()
            endif
        endif
    endfunction

    private function init takes nothing returns nothing
        call RegisterFunction("Wave13b", function Wave13b)
        call RegisterFunction("Wave13c", function Wave13c)
        //call ExecuteRegisteredFunction("Wave12b")
    endfunction
endlibrary